<template>
  <div class="film">
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
        v-if="movieArr"
      >
        <div class="draw">
          <div class="draw-list" v-for="(de, di) in movieArr" @click="jumpDetail(de.id)" :key="di">
            <div class="list">
              <!-- <img :src="`${de.img}`" alt="" /> -->
              <img v-lazy="de.img" :key="de.img" />
              <div class="txt">
                <!-- 上 -->
                <div class="txt-top">
                  <div class="txt-top-1">
                    <p class="top-p1">{{ de.nm }}</p>
                    <p class="top-p2">
                      {{ de.sc == 0 ? de.wish + "想看" : de.sc + "分" }}
                    </p>
                  </div>
                  <span class="txt-top-2">{{ de.enm }}</span>
                </div>
                <!-- 中 -->
                <div class="txt-center">
                  <p class="center-p1">
                    <span class="center-s1">
                      {{ /^[\u4e00-\u9fa5]{0,}/.exec(de.cat)[0] }}</span
                    >
                    {{ de.cat.split(",").splice(1).join() }}
                    <!-- {{ /^[\u4e00-\u9fa5]{0,}/.exec(de.cat)[0] }} -->
                  </p>
                </div>
                <!-- 下 -->
                <div class="txt-bottom">
                  <p>{{ de.star }}</p>
                  <p>{{ de.pubDesc }}</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </van-list>
    </van-pull-refresh>
  </div>
</template>
<script>
import { mapMutations } from "vuex";
import { List, PullRefresh } from "vant";
export default {
  name: "cartFilm",
  props: ["msg"],
  data() {
    return {
      movieArr: [],
      loadState: -1, //loading状态
      peoffset: 20, //初始化影片数据
      isAchiveBottom: false, //滚动条是否到底部标志
      finished: false, //数据是否加载完
      loading: false,
      refreshing: false,
    };
  },
  components: {
    [List.name]: List,
    [PullRefresh.name]: PullRefresh,
  },
  methods: {
    ...mapMutations(["changeSearchArray"]),
    onLoad() {
      if (this.refreshing) {
        this.movieArr = [];
        this.refreshing = false;
      }
      // 滑动调用方法
      this.getData(this.peoffset);
    },
    onRefresh() {
      // 清空列表数据
      this.finished = false;
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
    getData(k) {
      this.loadState = false;
      let pro = axios.get("search/movies", {
        params: {
          keyword: this.msg,
          cityId: 1,
          offset: k,
          //  offset: 20,
        },
      });
      pro.then((t) => {
        // // 加载状态结束
        // this.loading = false;
        console.log("请求成功----->", t);
        // 合并数组
        if (this.$store.state.searchArray.length == 0) {
          console.log("0000000", this.$store.state.homepageArray.length);
          //   赋值
          this.movieArr = [];
          this.movieArr = t.movies;
          //  存值
          this.changeSearchArray(this.movieArr);
        } else {
          console.log("每次更新数据----->", t.movies);
          this.movieArr = [];
          this.movieArr = this.$store.state.searchArray.concat(t.movies);
        }
        // 加载状态结束
        this.loading = false;

        //  存值
        this.changeSearchArray(this.movieArr);
        console.log("----数据--->", this.movieArr);
      });
    },
    //  处理 触底 数据
    changeData() {
      this.peoffset += 20;
      this.peoffset = this.peoffset;
      console.log("处理 触底 数据-----", this.peoffset);
      if (this.peoffset < 600) {
        this.getData(this.peoffset);
      } else {
        // 获取总数量，问题不大，
        this.peoffset = 600;
        console.log("没有更多了。。。");
      }
    },
    disposeData(t) {
      // 合并数组
      if (this.$store.state.searchArray.length == 0) {
        //   赋值
        this.movieArr = [];
        this.movieArr = t.movies;
        //  存值
        this.changeSearchArray(this.movieArr);
      } else {
        console.log("每次更新数据----->", t.movies);
        this.movieArr = [];
        this.movieArr = this.$store.state.searchArray.concat(t.movies);
        //  console.log(this.$store.state.homepageArray.length == 0 );
      }
      //  存值
      this.changeSearchArray(this.movieArr);
    },
    jumpDetail(k) {
      console.log(k);
      this.$router.push({ path: "/detail", query: { id: k } });
    },
  },
  mounted() {
    // this.getData(20);
    //   var pattern = /([\u4e00-\u9fa5]*)*/,
    // let str = "电视剧,剧情,喜剧,爱情";
    // console.log(str.split(",").splice(1));
    //  console.log(pattern.exec(str));
  },
};
</script>

<style lang="scss" scoped>
.film {
  width: 100%;
  height: 100%;
  position: relative;
}
// 渲染数据
.draw {
  .draw-list {
    background: rgb(248, 248, 248);
    .list {
      padding: 7px 0;
      border-radius: 7px;
      width: 352px;
      margin: 14px auto;
      display: flex;
      justify-content: space-between;
      img {
        width: 80px;
        height: 110px;
        border-radius: 6px;
        object-fit: cover;
      }
      // 文本区
      .txt {
        width: 255px;
        // 上
        .txt-top {
          width: 100%;
          height: 40px;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          align-content: flex-start;
          .txt-top-1 {
            display: flex;
            justify-content: space-between;
            .top-p1 {
              font-size: 16px;
              color: #000;
              font-weight: bold;
            }
            .top-p2 {
              font-size: 14px;
              color: #ffa82e;
            }
          }
          .txt-top-2 {
            display: inline-block;
            font-size: 12px;
            flex-wrap: 300;
          }
        }
        // 中
        .txt-center {
          margin: 3px 0;
          display: flex;
          justify-content: space-between;
          align-items: center;
          .center-p1 {
            font-size: 14px;
            .center-s1 {
              font-size: 10px;
              box-sizing: border-box;
              color: #67a6ff !important;
              border-radius: 3px;
              border: 1px solid #85a9da !important;
            }
          }
          .center-p2 {
            padding: 6px 14px;
            border-radius: 18px;
            font-size: 14px;
            background: #faaf00;
            color: rgb(245, 245, 245);
          }
        }

        // 下
        .txt-bottom {
          p {
            font-size: 10px;
            padding: 3px 0;
          }
        }
      }
    }
  }
  .draw-list:first-child {
    margin: 0 auto 14px;
  }
  .list:first-child {
    padding: 0px auto 14px;
    margin: 0 auto 14px;
  }
  .draw-p {
    background: rgb(248, 248, 248);
    font-size: 16px;
    color: #f34c40;
    // padding: 1px 0;
    width: 100%;
    height: 50px;
    text-align: center;
    line-height: 50px;
  }
}
.loading {
  width: 100px;
  height: 30px;
  border-radius: 7px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  background: rgba(0, 0, 0, 0.3);
}
.text-flowLight {
  position: relative;
  width: 100px;
  text-align: center;
  line-height: 30px;
  background-image: -webkit-linear-gradient(
    left,
    #b1c0ff,
    #b3ffb3,
    #ffbaba 100%
  );
  -webkit-text-fill-color: transparent;
  -webkit-background-clip: text;
  -webkit-background-size: 200% 100%;
  -webkit-animation: masked-animation 2s forwards linear infinite;
  font-weight: 700;
  white-space: nowrap;
  font-size: 16px;
}
@keyframes masked-animation {
  from {
    background-position: 0 0;
  }
  to {
    background-position: -200% 0;
  }
}
</style>